﻿using System;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using DAL;
using Common;


public partial class Business_SelectDanNum : System.Web.UI.Page
{
    protected string ParentID
    {
        get { return string.IsNullOrEmpty(Request["ParentID"])?"":Request["ParentID"].ToString();  }
    }
    protected string UserNameID
    {
        get { return string.IsNullOrEmpty(Request["UserNameID"]) ? "" : Request["UserNameID"].ToString(); }
    }
    protected string ParentID1
    {
        get { return string.IsNullOrEmpty(Request["ParentID1"]) ? "" : Request["ParentID1"].ToString(); }
    }

    protected int CurPage;

    protected int PageSize = Convert.ToInt32(ConfigurationSettings.AppSettings["PageSize"]);

    protected string IsShow
    {
        get
        {
            if ((string.IsNullOrEmpty(Request["query"]) ? "no" : Request["query"].ToString()) == "yes")
                return "block";
            else
                return "none";
        }
    }

    protected string Type
    {
        get { return string.IsNullOrEmpty(Request["type"]) ? "" : Request["type"].ToString(); }
    }


    protected int ClsIDType
    {
        get { return string.IsNullOrEmpty(Request["ClsIDType"]) ? 0 : Convert.ToInt32(Request["ClsIDType"]); }
    }

    protected string MenuType
    {
        get { return string.IsNullOrEmpty(Request["menutype"]) ? "" : Request["menutype"].ToString(); }
    }



    protected void Page_Load(object sender, EventArgs e)
    {
        CurPage = string.IsNullOrEmpty(Request["curpage"]) ? 1 : Convert.ToInt32(Request["curpage"]);

        if (!this.IsPostBack)
        {
            List<NewsType> NewsTypeList = new Sys_Para().SelectNewsType();
            foreach (NewsType nt in NewsTypeList)
                ClsID.Items.Add(new ListItem("┣ " + nt.TypeName, nt.TypeKey.ToString()));

            OneDate.Attributes.Add("onclick", "selectDate(this)");
            TwoDate.Attributes.Add("onclick", "selectDate(this)");


            //条件 Hashtable

            Hashtable tb = new Hashtable();
            bool QueryAdd = false;

            if (Type == "notfinish")
            {
                tb.Add("Type", "1,2,4,5");
                QueryAdd = true;
            }
            else if (Type == "waitdo")
            {
                tb.Add("Type", "1");
                QueryAdd = true;
            }
            else if (Type == "finish")
            {
                tb.Add("Type", "6");
                QueryAdd = true;
            }

            if (ClsIDType != 0)
            {
                tb.Add("ClsIDType", ClsIDType);
                QueryAdd = true;
            }

            if (!string.IsNullOrEmpty(Request.QueryString["ClsID"]))
            {   
                tb.Add("ClsID", Request["ClsID"].ToString());
                QueryAdd = true;
                ClsID.SelectedValue = Request.QueryString["ClsID"].ToString();
            }
            if (!string.IsNullOrEmpty(Request.QueryString["Keyword"]))
            {
                tb.Add("Keyword", Request.QueryString["Keyword"].ToString().Trim());
                QueryAdd = true;
                Keyword.Text = Request.QueryString["Keyword"].ToString().Trim();
            }
            if (!string.IsNullOrEmpty(Request.QueryString["OneDate"]))
            {
                tb.Add("OneDate", Request.QueryString["OneDate"].ToString().Trim());
                QueryAdd = true;
                OneDate.Text = Request["OneDate"].ToString().Trim();
            }
            if (!string.IsNullOrEmpty(Request.QueryString["TwoDate"]))
            {
                tb.Add("TwoDate", Request.QueryString["TwoDate"].ToString().Trim());
                QueryAdd = true;
                TwoDate.Text = Request.QueryString["TwoDate"].ToString().Trim();
            }
            tb = QueryAdd ? tb : null;

            NewsDataBind(tb);
        }
    }

    private void NewsDataBind(Hashtable QueryTable)
    {
        string URL = "SelectDanNum.aspx?menutype=" + MenuType + "&query=" + WebUtility.GetRequestString("query") + "&type=" + Type;

        Pager1.SetPageInfo(CurPage, new News().SelectNewsCount(QueryTable), URL, QueryTable);

        Re_News.DataSource = new News().SelectNews(QueryTable, CurPage);
        Re_News.DataBind();
    }

    //搜索
    protected void submit_Click(object sender, EventArgs e)
    {
        CurPage = 1;

        Hashtable tb = new Hashtable();
        bool QueryAdd = false;

        //条件 Hashtable
        if (Type == "finish")
        {
            tb.Add("Type", "1,2,3,4,5");
            QueryAdd = true;
        }
        else if (Type == "waitdo")
        {
            tb.Add("Type", "1");
            QueryAdd = true;
        }
        else if (Type == "notfinish")
        {
            tb.Add("Type", "6");
            QueryAdd = true;
        }
        if (!string.IsNullOrEmpty(ClsID.SelectedValue))
        {
            tb.Add("ClsID", ClsID.SelectedValue);
            QueryAdd = true;
        }
        if (!string.IsNullOrEmpty(Keyword.Text.Trim()))
        {
            tb.Add("Keyword", Keyword.Text.Trim());
            QueryAdd = true;
        }
        if (OneDate.Text.Trim() != "选择开始日期")
        {
            tb.Add("OneDate", OneDate.Text.Trim());
            QueryAdd = true;
        }
        if (TwoDate.Text.Trim() != "选择结束日期")
        {
            tb.Add("TwoDate", TwoDate.Text.Trim());
            QueryAdd = true;
        }
        tb = QueryAdd ? tb : null;

        NewsDataBind(tb);
    }

    protected string GetRadioContent(object obj1,object obj2,object obj3)
    {   
        string str = "";
        if (obj1 != null)
            str += obj1.ToString() + "$";
        else
            str += "" + "$";
        if (obj2 != null)
            str += obj2.ToString() + "$";
        else
            str += "" + "$";
        if (obj3 != null)
            str += obj3.ToString() ;
        else
            str += "" ;

        return str;
    }
}
